package calculator;

import junit.framework.TestCase;

public class CalculatorTest extends TestCase {
	private String input1;
	private String input2;
	private String input3;
	private String input4;
	private String input5;
	private String input6;
	private String input7;
	
	protected void setUp() throws Exception {
		super.setUp();
		input1 = "4 -5 -";
		input2 = "4 5 + 7 *";
		input3 = " 4 5 7 * + ";
		input4 = "  4 5 + 5  15 +  * 15 45 + / ";
		input5 = " 4 5 5 * + 15 15 / + 45 +";
		input6 = "3  0.14159 +  2 / sin ceil  9 sqrt + ";
		input7 = " -7.3891 abs -1.5 3 ^ abs max log";
	}
	
	public void testCalculation() {
		Calculator calc = new Calculator();
		assertEquals( 9.0, calc.calculate_upn(input1) );
		assertEquals( 63.0, calc.calculate_upn(input2));
		assertEquals( 39.0, calc.calculate_upn(input3));
		assertEquals( 3.0, calc.calculate_upn(input4));
		assertEquals( 75.0, calc.calculate_upn(input5));
		assertEquals(4.0, calc.calculate_upn(input6));
		// Abweichung vom exakten Wert 2.0 von 0.6e-5 erlaubt
		assertEquals(2.0, calc.calculate_upn(input7),0.6e-5);
	}
}
